package ContainerLayer;
import java.util.ArrayList;

/**
 * Write a description of class Product here.
 * ProductDescription is container for ProductNo and Rabat
 * The class holds an ArrayList of type ProductNo and one Rabat object
 * @author (your name) 
 * @version (a version number or a date)
 */
public class ProductDescription
{
    // instance variables - replace the example below with your own
    private long id; // id 
    private double price; //price for the descripted item
    private String description; // description
    private int minNo; //minimum number before new delivery 
    private ArrayList<ProductNo> products;
    private Rabat rabat;

    /**
     * Constructor for objects of class Product
     */
    public ProductDescription(long id, String description, double price, int minNo)
    {
        // initialise instance variables
        this.id = id;        
        this.price = price;
        this.description = description;
        this.minNo = minNo;
        products = new ArrayList<ProductNo>();        
    }

    public void setID(long id)
    {
        this.id = id;
    }

    public void setPrice(double price)
    {
        this.price = price;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }

    public void setMinNo(int minNo)
    {
        this.minNo = minNo;
    }

    public long getID()
    {
        return id;
    }    

    public double getPrice()
    {
        return price;
    }

    public String getDescription()
    {
        return description;
    }

    public int getMinNo()
    {
        return minNo;
    }

    public void addProductNo(ProductNo product)
    {
        if(!products.equals(product))
        {
            products.add(product);
        }
        else
        {
            System.out.println("There is already a product with the typed name");
        }      
    
    }

    public ProductNo readProductNo(long no)
    {
        int index = 0; 
        int productIndex = 0;
        boolean found = false;

        while(index < products.size() && !found)
        {
            if(products.get(index).getStoreNo() == no)
            {                
                found = true; 
                productIndex = index;
            }
            index++;
        }
        if(found)
        {
            return products.get(productIndex);
        }

        else
        {
            return null;
        }
    }

    public void updateProductNo(long no, boolean status)
    {
        int index = 0;
        int productIndex = 0;
        boolean found = false;

        while(index < products.size() && !found)
        {
            if(products.get(index).getStoreNo() == no)
            {
                found = true;
                productIndex = index;
            }          
            index++;
        }

        //If found, the filled parametre will be set
        // if not, the unfilled parametre will not be set
        if(found)
        {
            ProductNo p = products.get(productIndex);
            if(no != 0)
            {
                p.setStoreNo(no);
            }
            if(status != false) //?????
            {
                p.setStoreStatus(status);
            }            
        }

        else
        {
            System.out.println("There is no items with the typed Number,  - try again with another number");
        }
    }

    public void deleteProductNo(long no)
    {
        int index = 0;
        boolean deleted = false;
        while(index < products.size() && !deleted)
        {
            if(products.get(index).getStoreNo() == no)
            {
                products.remove(index);
                deleted = true;
            }
            index++;                       
        }       

        if(!deleted)
        {
            System.out.println("There is no items with the typed no, - try again with another no");
        }
    }

    public void printAllProductNo()
    {
        System.out.println("    SHOWS INFORMATION ABOUT ALL REGISTERED Salesmen");
        if(products != null)
        {
            for(ProductNo p : products)
            {
                System.out.println("############################################################");
                System.out.println("# Item number: "+p.getStoreNo());
                System.out.println("#  ---------------------------------------------------------");
                System.out.println("#      status: "+p.getStoreStatus());                               
                System.out.println("#");                
                System.out.println("########   THE END  for item no: "+p.getStoreNo());
                System.out.println("");                
            }
        }
        else
        {
            System.out.println("           >>There is no items registred<<");
            System.out.println();
        }
    }

    public void printOneProductNo(long no)
    {
        int index = 0; 
        int productIndex = 0;
        boolean found = false;

        while(index < products.size() && !found)
        {
            if(products.get(index).getStoreNo() == no)
            {                
                found = true; 
                productIndex = index;                
            }
            index++;
        }
        ProductNo p = products.get(productIndex);
        if(found)
        {
                System.out.println("############################################################");
                System.out.println("# Item number: "+p.getStoreNo());
                System.out.println("#  ---------------------------------------------------------");
                System.out.println("#      status: "+p.getStoreStatus());                               
                System.out.println("#");                
                System.out.println("########   THE END  for item no: "+p.getStoreNo());
                System.out.println("");   
        }

        else
        {
            System.out.println("           >>There is no items with the typed number"+no+"<<");
            System.out.println();
        }
    
    }
    
    public int getProductNoSize()
    {
        return products.size();
    }
    //Rabat
    public void addRabat()
    {
        rabat = new Rabat();
    }

    public void readRabat()
    {}

    public void updateRabat()
    {}

    public void deleteRabat()
    {}

    public void printAllRabat()
    {}
    
    public void printoneRabat()
    {}

}

